<?php

declare(strict_types=1);

namespace App\Controller;
use Hyperf\DbConnection\Db;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;

#[Controller(prefix: '/info')]
class Info extends AbstractController
{
    #[GetMapping(path:'read')]
    public function read()
    {
        return Db::table('info')->get()->toArray();
    }

    #[GetMapping(path:'write')]
    public function write()
    {
        $data = [
            'name' => $this->request->input('name'),
        ];
        Db::table('info')->insert($data);
        return 'ok';
    }


    #[GetMapping(path:'delete')]
    public function delete()
    {
        $id = $this->request->input('id');
        Db::table('info')->where('id', $id)->delete();
        return 'ok';
    }


    #[GetMapping(path:'update')]
    public function update()
    {
        $id = $this->request->input('id');
        $name = $this->request->input('name');
        Db::table('info')->where('id', $id)->update(['name' => $name]);
        return 'ok';
    }
}
